package com.young.shop.controller;

import com.young.shop.pojo.entity.OrdersChange;
import com.young.shop.service.OrderService;
import com.young.shop.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/chang")
public class OrdersStateChange extends BaseController {
    OrderService orderService = new OrderServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        OrdersChange ordersChange = convertParamsToEntity(req, OrdersChange.class);
        int id = ordersChange.getId();
        int status = ordersChange.getStatus();
        try {
            int i = orderService.stateChangeService(id, status);
            writerSuccessResult(i,resp);
        } catch (SQLException e) {
            writerErrorResult(e.getMessage(),resp);
        }
    }
}
